﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Model;


namespace DQYT.HTDZ.Web.Views.SystemManage
{
    public partial class bdjtwell : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            #region
            try
            {
                lblMsg.Text = "";
                BDMenuBLL menuBLL = new BDMenuBLL();
                lblPath.Text = menuBLL.GetTitlePath(Request["mnu_id"]);
                if (!IsPostBack)
                {
                    if (Request["action"] == "add")
                    {
                        btnEdit.Visible = false;
                    }
                    if (Request["action"] == "update")
                    {
                        btnAdd.Visible = false;
                    }
                    if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                    {
                        string WELLID = Request.Params["id"];
                        ShowInfo(WELLID);
                    }
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message;
            }
            #endregion
        }
        //更新时初始化
        private void ShowInfo(string WELLID)
        {
            BDJTWELLBLL bll = new BDJTWELLBLL();
            BDJTWELLModel model = bll.GetModel(WELLID);
            this.GQID.Text = model.GQID;
            this.WELLID.Text = model.WELLID;
            this.TYJM.Text = model.TYJM;
            this.BZJM.Text = model.BZJM;
            this.KZRQ.Text = model.KZRQ.ToString();
            this.DLWZ.Text = model.DLWZ;
            this.WD.Text = model.WD.ToString();
            this.JD.Text = model.JD.ToString();
            if (model.SFPTJ.ToString() == "1")
                this.SFPTJ.SelectedValue = "1";
            else
                this.SFPTJ.SelectedValue = "0";

            if (model.SFHSJ.ToString() == "1")
                this.SFHSJ.SelectedValue = "1";
            else
                this.SFHSJ.SelectedValue = "0";

            if (model.SFHDJ.ToString() == "1")
                this.SFHDJ.SelectedValue = "1";
            else
                this.SFHDJ.SelectedValue = "0";

            this.SS.Text = model.SS.ToString();

        }

        //添加
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            #region
            try
            {
                string strErr = "";
                if (this.GQID.Text.Trim().Length == 0)
                {
                    strErr += "工区号不能为空！\\n";
                }
                if (this.WELLID.Text.Trim().Length == 0)
                {
                    strErr += "WELLID不能为空！\\n";
                }
                if (this.TYJM.Text.Trim().Length == 0)
                {
                    strErr += "TYJM不能为空！\\n";
                }
                if (this.BZJM.Text.Trim().Length == 0)
                {
                    strErr += "BZJM不能为空！\\n";
                }
                if (!PageValidate.IsDateTime(this.KZRQ.Text))
                {
                    strErr += "KZRQ格式错误！\\n";
                }
                if (this.DLWZ.Text.Trim().Length == 0)
                {
                    strErr += "DLWZ不能为空！\\n";
                }
                   if (!PageValidate.IsDecimal(this.WD.Text))
                {
                    strErr += "WD格式错误！\\n";
                }
                if (!PageValidate.IsDecimal(this.JD.Text))
                {
                    strErr += "JD格式错误！\\n";
                }
                
                if (!PageValidate.IsDecimal(this.SS.Text))
                {
                    strErr += "SS格式错误！\\n";
                }

                if (strErr != "")
                {
                    MessageBox.Show(this, strErr);
                    return;
                }
                string GQID = this.GQID.Text;
                string WELLID = this.WELLID.Text;
                string TYJM = this.TYJM.Text;
                string BZJM = this.BZJM.Text;
                DateTime KZRQ = DateTime.Parse(this.KZRQ.Text);
                string DLWZ = this.DLWZ.Text;
                decimal WD = decimal.Parse(this.WD.Text);
                decimal JD = decimal.Parse(this.JD.Text);
                decimal SFPTJ = decimal.Parse(this.SFPTJ.SelectedValue);
                decimal SFHSJ = decimal.Parse(this.SFHSJ.SelectedValue);
                decimal SFHDJ = decimal.Parse(this.SFHDJ.SelectedValue);
                decimal SS = decimal.Parse(this.SS.Text);

                BDJTWELLModel model = new BDJTWELLModel();
                model.GQID = GQID;
                model.WELLID = WELLID;
                model.TYJM = TYJM;
                model.BZJM = BZJM;
                model.KZRQ = KZRQ;
                model.DLWZ = DLWZ;
                model.WD = WD;
                model.JD = JD;
                model.SFPTJ = SFPTJ;
                model.SFHSJ = SFHSJ;
                model.SFHDJ = SFHDJ;
                model.SS = SS;

                BDJTWELLBLL bll = new BDJTWELLBLL();
                bll.Add(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "BdjtwellManage.aspx");
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message;
            }
            #endregion
        }

        //修改
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            #region
            try
            {
                string strErr = "";
                if (this.GQID.Text.Trim().Length == 0)
                {
                    strErr += "工区号不能为空！\\n";
                }
                if (this.WELLID.Text.Trim().Length == 0)
                {
                    strErr += "WELLID不能为空！\\n";
                }
                if (this.TYJM.Text.Trim().Length == 0)
                {
                    strErr += "TYJM不能为空！\\n";
                }
                if (this.BZJM.Text.Trim().Length == 0)
                {
                    strErr += "BZJM不能为空！\\n";
                }
                if (!PageValidate.IsDateTime(this.KZRQ.Text))
                {
                    strErr += "KZRQ格式错误！\\n";
                }
                if (this.DLWZ.Text.Trim().Length == 0)
                {
                    strErr += "DLWZ不能为空！\\n";
                }
                if (!PageValidate.IsDecimal(this.WD.Text))
                {
                    strErr += "WD格式错误！\\n";
                }
                if (!PageValidate.IsDecimal(this.JD.Text))
                {
                    strErr += "JD格式错误！\\n";
                }

                if (!PageValidate.IsDecimal(this.SS.Text))
                {
                    strErr += "SS格式错误！\\n";
                }

                if (strErr != "")
                {
                    MessageBox.Show(this, strErr);
                    return;
                }
                string GQID = this.GQID.Text;
                string WELLID = this.WELLID.Text;
                string TYJM = this.TYJM.Text;
                string BZJM = this.BZJM.Text;
                DateTime KZRQ = DateTime.Parse(this.KZRQ.Text);
                string DLWZ = this.DLWZ.Text;
                decimal WD = decimal.Parse(this.WD.Text);
                decimal JD = decimal.Parse(this.JD.Text);
                decimal SFPTJ = decimal.Parse(this.SFPTJ.SelectedValue);
                decimal SFHSJ = decimal.Parse(this.SFHSJ.SelectedValue);
                decimal SFHDJ = decimal.Parse(this.SFHDJ.SelectedValue);
                decimal SS = decimal.Parse(this.SS.Text);

                BDJTWELLModel model = new BDJTWELLModel();
                model.GQID = GQID;
                model.WELLID = WELLID;
                model.TYJM = TYJM;
                model.BZJM = BZJM;
                model.KZRQ = KZRQ;
                model.DLWZ = DLWZ;
                model.WD = WD;
                model.JD = JD;
                model.SFPTJ = SFPTJ;
                model.SFHSJ = SFHSJ;
                model.SFHDJ = SFHDJ;
                model.SS = SS;

                BDJTWELLBLL bll = new BDJTWELLBLL();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "修改成功！", "BdjtwellManager.aspx");
            }
            catch (Exception ex)
            {
                lblMsg.Text = "错误信息：" + ex.Message;
            }
            #endregion

        }
    }
}